package cn.daniel.oss.controller;

import cn.daniel.commonutils.Response;
import cn.daniel.commonutils.exceptionhandler.exception.MyException;
import cn.daniel.commonutils.result.ResultCode;
import cn.daniel.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "阿里云OSS文件上传")
@RestController
@RequestMapping("/service/oss")
public class OssController {

    @Autowired
    private OssService ossService;
    @ApiOperation("上传图片文件")
    @PostMapping("/uploadPhotoFile")
    public Response uploadPhotoFile(@ApiParam("图片文件") MultipartFile file){
        System.out.println(file.toString());
        if (file.isEmpty()){
            throw MyException.setException(ResultCode.FILE_EMPTY);
        }else {
            String url =ossService.uploadPhotoFile(file);
            return Response.ok().data("url",url);
        }


    }

}
